<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\model\RolesUserRelation as RolesUserRelationModel;

class RolesUserRelation extends Base
{

    /**
     * 角色列表
     * @param $page 页面
     * @param $pagesize 每页大小
     * @return \think\response\Json
     */
    public function roleslist($page,$pagesize){
        try {
            $RolesModel = new RolesModel();
            $list = $RolesModel->RolesList($page,$pagesize);
            return json($list);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 新增角色
     * @param $rolesname
     * @param $exp_time
     * @param int $status
     * @return \think\response\Json
     */
    public function rolesadd($rolesname,$exp_time,$status=1){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesAdd($rolesname,$exp_time,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 保存角色
     * @param $roles_id
     * @param $rolesname
     * @param $exp_time
     * @return \think\response\Json
     */
    public function rolesedit($roles_id,$rolesname,$exp_time){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesEdit($roles_id,$rolesname,$exp_time);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色启/禁用
     * @param $roles_id
     * @param $status
     * @return \think\response\Json
     */
    public function rolessetstatus($roles_id,$status){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesSetStatus($roles_id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 角色删除
     * @param $roles_id
     * @return \think\response\Json
     */
    public function rolesdel($roles_id){
        try {
            $RolesModel = new RolesModel();
            $res = $RolesModel->RolesDel($roles_id);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

}
